package com.yc.thread.pro1_matrix.row;

/**
 * @author zwei
 * @create 2024-07-17 15:52
 */

/**
 * 基于结果矩阵的任务类：结果矩阵每一行一个任务
 * 总共产生2000个任务
 */
public class rowMultiplierTask implements Runnable {
    private final double[][] result;     //final：确保线程的安全性
    private final double[][] matrix1;
    private final double[][] matrix2;
    private final int row;

    public rowMultiplierTask(double[][] result, double[][] matrix1, double[][] matrix2, int row) {
        this.result = result;
        this.matrix1 = matrix1;
        this.matrix2 = matrix2;
        this.row = row;
    }


    @Override
    public void run() {
        for (int j = 0; j < matrix2[0].length; j++) {
            result[row][j] = 0;
            //累加求和
            for (int k = 0; k < matrix1[0].length; k++) {
                result[row][j] += matrix1[row][k] * matrix2[k][j];
            }
        }
    }
}
